#include<stdio.h>
int main()
{
	int s[10000];int i=0; 
	const char *a[100]={"I","II","III","IV","V","VI","VII","VIII","IX"};
	const char *b[100]={"X","XX","XXX","XL","L","LX","LXX","LXXX","XCC"};
	const char *c[100]={"C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
    while(6){
	scanf("%d",&s[i]);
	if(s[i]<0)
	printf("Input Error\n");
	if(s[i]==0)
	{
	printf("End Of Input\n");
	break;}
	int x=s[i]/100;
	int y=0;if(s[i]-x*100<10){y=0;}else{y=(s[i]-x*100)/10;}
	int z=s[i]-x*100-y*10;
	if(s[i]>0)
	{
		if(s[i]>=100&&y!=0&&z!=0)
		{
		printf("%s",c[x-1]);
		printf("%s",b[y-1]);
		printf("%s\n",a[z-1]);}
		if(s[i]>=100&&y!=0&&z==0)
		{
			printf("%s",c[x-1]);
		printf("%s\n",b[y-1]);
		}
		if(s[i]>=100&&y==0&&z!=0)
		{
				printf("%s",c[x-1]);
				printf("%s\n",a[z-1]);
		}
		if(s[i]>=100&&y==0&&z==0)
		{
			printf("%s\n",c[x-1]);
		}
	if(10<=s[i]&&s[i]<100&&z!=0)
	{
			printf("%s",b[(s[i]/10)-1]);
		printf("%s\n",a[s[i]-(s[i]/10)*10-1]);
	}
	if(10<=s[i]&&s[i]<100&&z==0)
	{
			printf("%s\n",b[(s[i]/10)-1]);
	}
	if(s[i]<10&&s[i]>0)
	{
			printf("%s\n",a[s[i]-1]);
			
	}
}
i++;
}
return 0;
 } 
